package com.huawei.hotel.service.impl;

import com.huawei.hotel.common.utils.Page;
import com.huawei.hotel.dao.StudentDao;
import com.huawei.hotel.service.StudentService;
import com.huawei.hotel.vo.Student;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("studentService")
@Transactional
public class StudentServiceImpl implements StudentService {
    //注入UserDao
    @Autowired(required=true)
    private StudentDao studentDao;

    @Override
    public Page<Student> findStudentList(Integer page, Integer rows, String stu_name, String stu_acount) {
        //创建对象
        Student student=new Student ();
        //判断学生姓名
        if(StringUtils.isNotBlank (stu_name)){
            student.setStu_name (stu_name);
        }
        //判断学生学号
        if(StringUtils.isNotBlank (stu_acount)){
            student.setStu_acount (stu_acount);
        }
        //当前页面
        student.setStart ((page-1)*rows);
        student.setRows (rows);
        //查询学生列表
        List<Student> students=studentDao.selectStudentList(student);
        //查询学生列表总计数
        Integer count=studentDao.selectStudentListCount(student);
        //创建page返回对象
        Page<Student> result=new Page<> ();
        result.setPage (page);
        result.setRows (students);
        result.setSize (rows);
        result.setTotal (count);
        return result;
    }

}
